const expect = @import("std").testing.expect;

// Defer 可用于确保在不再需要资源时清理资源。无需记住手动释放资源，只需在分配资源的语句旁边添加 defer 语句。
test "defer" {
    var x: i16 = 5;
    {
        defer x += 2;
        try expect(x == 5);
    }
    try expect(x == 7);
}

test "multi defer" {
    var x: f32 = 5;
    {
        defer x += 2;
        defer x /= 2;
    }
    try expect(x == 4.5);
}
